package org.resort.service.impl;

import org.resort.dao.*;
import org.resort.entity.*;
import org.resort.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author 郭文虎
 * <p>
 * 客房服务
 */
@Service("roomService")
public class RoomServiceImpl implements RoomService {

    @Autowired
    RoomDao roomDao;
    @Autowired
    RoomOrderDao roomOrderDao;
    @Autowired
    ExitRoomDao exitRoomDao;
    @Autowired
    AppendRoomDao appendRoomDao;
    @Autowired
    RoomTypeDao roomTypeDao;
    @Autowired
    RoomOrderInfoDao roomOrderInfoDao;
    @Autowired
    EmployeeDao employeeDao;

    @Override
    public List<RoomOrder> getAll() {
        return roomOrderDao.getAllEntity();
    }

    @Override
    public List<ExitRoom> getAllExits() {
        return exitRoomDao.getAllEntity();
    }

    @Override
    public int addRoomOrder(Date startdate, Date enddate, int memberid, int employeeid, int stateid, Double day) {
        RoomOrder roomOrder = new RoomOrder();
        roomOrder.setStartdate(startdate);
        roomOrder.setEnddate(enddate);
        roomOrder.setDay(day);
        Member member = new Member();
        member.setId(memberid);
        Employee employee = new Employee();
        employee.setId(employeeid);
        State state = new State();
        state.setId(stateid);
        roomOrder.setEmployee(employee);
        roomOrder.setMember(member);
        roomOrder.setState(state);
        return roomOrderDao.addOneEntity(roomOrder);
    }

    @Override
    public int delectRoomOrder(int id) {
        return roomOrderDao.delOneEntityById(id);
    }

    @Override
    public RoomOrder getRoomOrderById(int id) {
        return roomOrderDao.getEntityById(id);
    }

    @Override
    public int updateRoomOrder(int id, Date startdate, Date enddate, int memberid, int employeeid, int stateid, Double day) {
        RoomOrder roomOrder = new RoomOrder();
        roomOrder.setId(id);
        roomOrder.setStartdate(startdate);
        roomOrder.setEnddate(enddate);
        roomOrder.setDay(day);
        Member member = new Member();
        member.setId(id);
        Employee employee = new Employee();
        employee.setId(id);
        State state = new State();
        state.setId(id);
        roomOrder.setMember(member);
        roomOrder.setEmployee(employee);
        roomOrder.setState(state);
        return roomOrderDao.changeEntityById(roomOrder);
    }

    @Override
    public List<AppendRoom> getAllAppendRoom() {
        return appendRoomDao.getAllEntity();
    }

    @Override
    public List<RoomType> getAllType() {
        return roomTypeDao.getAllEntity();
    }

    @Override
    public List<Room> getRoom() {
        return roomDao.getAllEntity();
    }

    @Override
    public List<RoomOrderInfo> getRoomOrderInfo() {
        return roomOrderInfoDao.getAllEntity();
    }

    @Override
    public int AddExitRoom(int roomorderid, Date date, int dustmanid) {
        ExitRoom exitRoom = new ExitRoom();
        exitRoom.setDate(date);
        RoomOrder roomOrder = new RoomOrder();
        roomOrder.setId(roomorderid);
        Employee employee = new Employee();
        employee.setId(dustmanid);
        exitRoom.setOrder(roomOrder);
        exitRoom.setDustman(employee);

        exitRoom.show();
        return exitRoomDao.addOneEntity(exitRoom);
    }

    @Override
    public int getAddAppentRoom(int roomorderid, Date appenddate) {
        AppendRoom appendRoom = new AppendRoom();
        appendRoom.setDate(appenddate);
        RoomOrder roomOrder = new RoomOrder();
        roomOrder.setId(roomorderid);
        appendRoom.setOrder(roomOrder);
        return appendRoomDao.addOneEntity(appendRoom);
    }

    @Override
    public int AddRoomType(String name, String descriptor) {
        RoomType roomType = new RoomType();
        roomType.setName(name);
        roomType.setDescriptor(descriptor);
        return roomTypeDao.addOneEntity(roomType);
    }

    @Override
    public int addRoom(String name, int typeid, int stateid) {
        Room room = new Room();
        room.setName(name);
        RoomType roomType = new RoomType();
        roomType.setId(typeid);
        State state = new State();
        state.setId(stateid);
        room.setState(state);
        room.setType(roomType);
        return roomDao.addOneEntity(room);
    }

    @Override
    public int addroomorderinfo(int roomid, int roomorderid) {
        RoomOrderInfo roomOrderInfo = new RoomOrderInfo();
        Room room = new Room();
        room.setId(roomid);
        RoomOrder roomOrder = new RoomOrder();
        roomOrder.setId(roomorderid);
        roomOrderInfo.setRoom(room);
        roomOrderInfo.setOrder(roomOrder);
        return roomOrderInfoDao.addOneEntity(roomOrderInfo);
    }

    @Override
    public int updateExitRoom(int id, int roomorderid, Date date, int dustmanid) {
        ExitRoom exitRoom = new ExitRoom();
        exitRoom.setId(id);
        exitRoom.setDate(date);
        RoomOrder roomOrder = new RoomOrder();
        roomOrder.setId(roomorderid);
        Employee employee = new Employee();
        employee.setId(dustmanid);
        exitRoom.setOrder(roomOrder);
        exitRoom.setDustman(employee);
        return exitRoomDao.changeEntityById(exitRoom);
    }

    @Override
    public ExitRoom getExitRoomById(int id) {
        return exitRoomDao.getEntityById(id);
    }

    @Override
    public AppendRoom getAppendRoomByid(int id) {
        return appendRoomDao.getEntityById(id);
    }

    @Override
    public int updateAppendRoom(int id, int roomorderid, Date appenddate) {
        AppendRoom appendRoom = new AppendRoom();
        appendRoom.setId(id);
        appendRoom.setDate(appenddate);
        RoomOrder roomOrder = new RoomOrder();
        roomOrder.setId(roomorderid);
        appendRoom.setOrder(roomOrder);
        return appendRoomDao.changeEntityById(appendRoom);
    }

    @Override
    public List<RoomOrder> getPartOrderByState(String stateName) {
        return roomOrderDao.getRoomOrderByState(stateName);
    }

    @Override
    public List<Employee> getAllDustman() {
        return employeeDao.getAllDustman();
    }

  /*  @Override
    public RoomType getAllRoomType() {
        return roomTypeDao.selectGet();
    }*/
}